package proxy
{
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	public class PhotoSearchProxy extends EventDispatcher
	{
		private static const API_KEY:String = "3a662c08a083c6b5c0744e364b559bec";
		private static const FLICKR_URL:String = "http://api.flickr.com/services/rest/";//?method=flickr.test.echo&name=value
		public function PhotoSearchProxy(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		public function search(userId:String,tags:String):void{
			var loader:URLLoader = new URLLoader;
			var url:String = FLICKR_URL + 
				"?method=flickr.photos.search&user_id" + userId + "&tags="
				+ tags + "&api_key=" + API_KEY;
			url = encodeURI(url);
			var request:URLRequest = new URLRequest(url);
			
			loader.addEventListener(Event.COMPLETE,onComplete);
			loader.load(request);
		}
		
		private function onComplete(event:Event):void{
			this.dispatchEvent(new DataEvent(Event.COMPLETE,false,false,XML(event.target.data)));
		}
		
	}
}